package com.bootdo.wx.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.wx.domain.TestDataDo;
import com.bootdo.wx.service.TestDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 检测参数
 *
 * Created by Administrator.
 *
 * @autor L - 2020/5/28 - 11:31.
 */

@Controller
@RequestMapping("/wx/deviceInfo/testData")
public class TestDataController {

    @Autowired
    private TestDataService testDataService;

    @GetMapping()
    @RequiresPermissions("wx:deviceInfo:testData")
    String TestData() {
        return "wx/deviceInfo/testData";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("wx:deviceInfo:testData")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<TestDataDo> orderInfoList = testDataService.list(query);
        int total = testDataService.count(query);
        PageUtils pageUtils = new PageUtils(orderInfoList, total);
        return pageUtils;
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("wx:deviceInfo:testData:add")
    public R save(TestDataDo orderInfo) {
        if (testDataService.save(orderInfo) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("wx:deviceInfo:testData:edit")
    public R update(TestDataDo orderInfo) {
        testDataService.update(orderInfo);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("wx:deviceInfo:testData:remove")
    public R remove(String id) {
        if (testDataService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 批量删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("wx:deviceInfo:testData:batchRemove")
    public R remove(@RequestParam("ids[]") String[] ids) {
        testDataService.batchRemove(ids);
        return R.ok();
    }

}
